home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-9.10-netbook-remix-PL.iso / casper / filesystem.squashfs / usr / share / software-center / softwarecenter / utils.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2009-10-28  |  2KB  |  47 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4.  
  5. class ExecutionTime(object):
  6.     '''
  7.     Helper that can be used in with statements to have a simple
  8.     measure of the timming of a particular block of code, e.g.
  9.     with ExecutinTime("db flush"):
  10.         db.flush()
  11.     '''
  12.     
  13.     def __init__(self, info = ''):
  14.         self.info = info
  15.  
  16.     
  17.     def __enter__(self):
  18.         self.now = time.time()
  19.  
  20.     
  21.     def __exit__(self, type, value, stack):
  22.         print '%s: %s' % (self.info, time.time() - self.now)
  23.  
  24.  
  25.  
  26. def encode_for_xml(unicode_data, encoding = 'ascii'):
  27.     ''' encode a given string for xml '''
  28.     return unicode_data.encode(encoding, 'xmlcharrefreplace')
  29.  
  30.  
  31. def decode_xml_char_reference(s):
  32.     """ takes a string like 
  33.         'Search…' 
  34.         and converts it to
  35.         'Search...'
  36.     """
  37.     import re as re
  38.     p = re.compile('\\&\\#x(\\d\\d\\d\\d);')
  39.     return p.sub('\\u\\1', s).decode('unicode-escape')
  40.  
  41. if __name__ == '__main__':
  42.     s = decode_xml_char_reference('Search…')
  43.     print s
  44.     print type(s)
  45.     print unicode(s)
  46.  
  47.